package cn.iocoder.yudao.module.product.controller.app.customermessage;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.product.controller.app.customermessage.vo.AppCustomerMessagePageReqVO;
import cn.iocoder.yudao.module.product.controller.app.customermessage.vo.AppCustomerMessageRespVO;
import cn.iocoder.yudao.module.product.controller.app.customermessage.vo.AppCustomerMessageReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.customermessage.CustomerMessageDO;
import cn.iocoder.yudao.module.product.service.customermessage.CustomerMessageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "APP - 客服消息")
@RestController
@RequestMapping("/product/customer-message")
@Validated
public class AppCustomerMessageController {

    @Resource
    private CustomerMessageService customerMessageService;

    @PostMapping("/create")
    @Operation(summary = "创建客服消息")
    public CommonResult<AppCustomerMessageRespVO> createCustomerMessage(@Valid @RequestBody AppCustomerMessageReqVO createReqVO) {
        return success(customerMessageService.createCustomerMessage(createReqVO));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除客服消息")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteCustomerMessage(@RequestParam("id") Long id) {
        customerMessageService.deleteCustomerMessage(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得客服消息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppCustomerMessageRespVO> getCustomerMessage(@RequestParam("id") Long id) {
        CustomerMessageDO customerMessage = customerMessageService.getCustomerMessage(id);
        return success(BeanUtils.toBean(customerMessage, AppCustomerMessageRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得客服消息分页")
    public CommonResult<PageResult<AppCustomerMessageRespVO>> getCustomerMessagePage(@Valid AppCustomerMessagePageReqVO pageReqVO) {
        PageResult<CustomerMessageDO> pageResult = customerMessageService.getCustomerMessagePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppCustomerMessageRespVO.class));
    }

}